package org.zjx.handler;

import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;

public class CommandHandlerFactory {
    private static final Map<String, CommandHandler> handlers = new ConcurrentHashMap<>();

    public static void registerHandler(CommandHandler handler) {
        handlers.put(handler.getCommand(), handler);
    }

    public static Optional<CommandHandler> getHandler(String command) {
        return Optional.ofNullable(handlers.get(command));
    }
}